package com.biostime.qdingding.modules.qd.service;


import java.text.SimpleDateFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.qdingding.modules.qd.dao.CourseOrderDao;
import com.biostime.qdingding.modules.qd.entity.Course;


/**
 * TipsService
 * @author chenweicheng
 * @version 2015-12-13
 */
@Service
@Transactional(readOnly = true)
public class TipsMessageService {
	
	@Autowired
	private CourseOrderDao orderDao;
	
	public String tips(Course course,Double money,String type){

		//提示信息
		SimpleDateFormat sdf =   new SimpleDateFormat("yyyy-MM-dd"); 
		String commonMessage = "课程信息："+sdf.format(course.getOndate())+" "+course.getSection()+" "+course.getClevel()
			+course.getSerial()+" "+course.getTheme();	;
		String tipsMessage = null;
		
		// 课程排位人数
		int courseQueue = orderDao.apiCourseQueue(course.getId(), String.valueOf(course.getType()));
		
		//按消息类型，返回消息内容
		switch(type){
		
			//预约
			case "ordered":
				tipsMessage = "您已预约成功该课程，"+commonMessage;
				break;
			
			//等位
			case "queuing":
				tipsMessage = "您预约的课程正在排队等候中，前面还有"+(courseQueue)+"人"+commonMessage;
				break;	
			
			//取消预约
			case "cancelOrder":
				tipsMessage = "您已成功取消预约该课程，"+commonMessage;				
				break;

			//取消预约后
			case "cancelOrderAfter":
				tipsMessage = "由于您加入等位的课程有人走了，所以您已成功预约，"+commonMessage;				
				break;
				
			//取消等位
			case "cancelQueuing":
				tipsMessage = "您已成功取消等位该课程，"+commonMessage;	
				break;		
			
			//请假
			case "leaved":
				tipsMessage = "您已成功请假该课程，"+commonMessage;	
				break;	
			
			//中止课程
			case "abort":
				tipsMessage = "您已成功中止该课程，"+commonMessage;	
				break;	
				
			//请假返款
			case "leavePrivilege":
				tipsMessage = "请假特权生效，"+money+"元扣费已返还，课程信息："+commonMessage;	
				break;
				
			//中止返款
			case "abortPrivilege":
				tipsMessage = "中止特权生效，"+money+"元扣费已返还，课程信息："+commonMessage;	
				break;		
				
			default:
				tipsMessage = "未识别消息";
				break;	
		}
				
		return tipsMessage;
	}
	
	
	
}
